package jCross.io;

import java.util.*;
import java.io.*;

public class IOUtil {
	public static final String SEPARATOR = "---";
	public static int wd = 1, ht = 1;
	public static int[][] upLevels = null, leftLevels = null;
	
	public static void loadData(String fileName) {
		try {
			BufferedReader br = new BufferedReader(new FileReader(fileName));
			String str = null;
			ArrayList<String> list = new ArrayList<String>();
			while((str = br.readLine()) != null) {
				if(SEPARATOR.equals(str)) {
					wd = list.size();
					upLevels = new int[wd][];
					int i = 0;
					for(String s : list) {
						String[] ss = s.split(",");
						upLevels[i] = new int[ss.length];
						for(int j = 0; j < ss.length; j++) {
							upLevels[i][j] = Integer.parseInt(ss[j].trim());
						}
						i++;
					}
					list.clear();
				} else {
					list.add(str);
				}
			}
			br.close();
			ht = list.size();
			leftLevels = new int[ht][];
			int i = 0;
			for(String s : list) {
				String[] ss = s.split(",");
				leftLevels[i] = new int[ss.length];
				for(int j = 0; j < ss.length; j++) {
					leftLevels[i][j] = Integer.parseInt(ss[j].trim());
				}
				i++;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
